    let ORDER_STATUS = {SUBMITED: '已提交', COMPLETED: '已完成', REJECT: '审核拒绝', CONFIRM: '已确认', CANCEL: '已取消'};
    let PAY_STATUS = {UNPAID: '未支付', PAID: '已支付', REFUNDING: '申请退款', REFUND_COMPLETED: '退款完成', CLOSED: '交易关闭'};
    let order = {
        $table: $('#orderList'),
        $statusList: $('#statusList'),
        $payStatusList: $('#payStatusList'),
    };
    let clearParams = function () {
        eyc.ui.clearValueUiElement($('form'));
    };
    let calcTableHeight = ($tableContainer) => {
        let paddingTop = $('body').css('padding-top');
        let bodyPaddingHeight = paddingTop.replace(/[^0-9]/ig, "");
        let height = $(window).height() - $tableContainer.offset().top - $(window).scrollTop() - bodyPaddingHeight;
        return height;
    };
    let initTable = () => {
        let colModel = [
            {
                align: "center",
                cb: {header: true, select: true, all: false},
                type: 'checkbox',
                dataType: 'bool',
                editor: false,
                sortable: false,
                minWidth: 50,
                width: 50
            }
            , {dataIndx: 'orderNum', title: '订单号', editable: false, minWidth: 100, align: "center"}
            , {
                dataIndx: 'status',
                title: '订单状态',
                editable: false,
                align: "center",
                minWidth: 100,
                render: function (ui) {
                    return ORDER_STATUS[ui.cellData];
                }
            }
            , {
                dataIndx: 'payStatus',
                title: '支付状态',
                editable: false,
                align: "center",
                minWidth: 100,
                render: function (ui) {
                    return PAY_STATUS[ui.cellData];
                }
            }
            , {dataIndx: 'userId', title: '客户', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'plateNum', title: '车牌号', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'createTime', title: '下单时间', editable: false, align: "center", minWidth: 150}
            , {dataIndx: 'verificationPerson', title: '核销人', editable: false, align: "center", minWidth: 120}
            , {dataIndx: 'verificationTime', title: '核销时间', editable: false, align: "center", minWidth: 150}
            , {dataIndx: 'company', title: '商户', editable: false, align: "center", minWidth: 180}
            , {dataIndx: 'price', title: '金额', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'preferentialPrice', title: '优惠金额', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'couponPrice', title: '优惠券', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'contact', title: '联系人', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'contactNum', title: '联系电话', editable: false, align: "center", minWidth: 100}
            , {dataIndx: 'remark', title: '备注', editable: true, align: "center", minWidth: 100}
            , {dataIndx: 'refundRemark', title: '申请退款原因', editable: true, align: "center", minWidth: 100}
        ];

        let option = {
            width: '100%',
            dataModel: {
                recIndx: "orderId",
                contentType: "application/json;charset=UTF-8",
                location: "remote",
                dataType: "JSON",
                method: "POST",
                url: "/eyc/searchOrders",
                postData: eyc.pqGrid.searchParam,
                getData: eyc.pqGrid.dataResponse,
                error: eyc.ajax.ajaxError
            },
            pageModel: {
                type: "remote",
                rPP: 50,
                curPage: 1,
                rPPOptions: [50, 100, 200]
            },
            sortModel: {
                type: 'remote',
                single: true
            },
            colModel: colModel,
            searchFormId: "#orderForm",
            scrollModel: {autoFit: false},
            showTop: false,
            numberCell: {show: false},
            virtualX: false,
            virtualY: true,
            wrap: false,
            rowSelect:rowSelect,
            height: calcTableHeight(order.$table),
            selectionModel: {type: 'cell',/*toggle: true,*/ mode: "single"}
        };
        eyc.pqGrid.init(order.$table, option);
    };
    let rowSelect=(event, ui)=>{
        let $velBtn=$('button[data-method="verificationOrders"]');
        let $refundBtn=$('button[data-method="confirmRefund"]');

        let selectRows = eyc.pqGrid.getSelectRows(order.$table);
        let isCanVel=true,isCanRefund=true;
        if(selectRows != null && selectRows.length > 0){
            $.each(selectRows, function(i,r){
                let rowData=r.rowData;
                isCanVel=isCanVel && (rowData.status==='CONFIRM' && rowData.payStatus==='PAID') ;
                isCanRefund=isCanRefund && (rowData.status==='CONFIRM' && rowData.payStatus==='REFUNDING') ;
            })
        }else{
            isCanVel=false;
            isCanRefund=false;
        }
        isCanVel?$velBtn.removeClass('layui-btn-disabled'):$velBtn.addClass('layui-btn-disabled');
        isCanRefund?$refundBtn.removeClass('layui-btn-disabled'):$refundBtn.addClass('layui-btn-disabled');
        $velBtn.prop("disabled",!isCanVel);
        $refundBtn.prop("disabled",!isCanRefund);
    };
    let initLaydate = (laydate) => {
        let opts = {
            theme: 'molv',
            type: 'date',
            format: 'yyyy-MM-dd'
        };
        $.each($('[lay-date-input]'), function (i, ele) {
            laydate.render($.extend({}, opts, {elem: ele}));
        });
    };

    let initSelectPage = () => {
        eyc.ajax.promise('/eyc/configTypeEnums', {method: 'GET', enumName: 'OrderStatusEnum'}).then(res => {
            order.$statusList.selectPage({
                showField: 'name',
                keyField: 'code',
                data: res.data,
                pagination: false,
                multiple: true
            });
        });
        eyc.ajax.promise('/eyc/configTypeEnums', {method: 'GET', enumName: 'PayStatusEnum'}).then(res => {
            order.$payStatusList.selectPage({
                showField: 'name',
                keyField: 'code',
                data: res.data,
                pagination: false,
                multiple: true
            });
        });
    };
    let search = () => {
        order.$table.pqGrid("refreshDataAndView");
    };
    let exportExcel=()=>{
        let postParam= $("#orderForm").serializeObject();
        downloadFile('/eyc/exportOrder',postParam);
    }
    let downloadFile=function(url,params){
        let temp = document.createElement("form");
        temp.action = encodeURI(url);
        temp.method = "get";
        temp.style.display = "none";
        if(typeof params !="undefined"){
            $.each(params,function(name,value){
                if(name=='uuids'){
                    $.each(value,function(i,v){
                        temp.appendChild(createElement(name,v));
                    });
                }else{
                    temp.appendChild(createElement(name,value));
                };
            });
        }
        document.body.appendChild(temp);
        temp.submit();
    };
    let createElement=function(name,value){
        let input = document.createElement("input");
        input.name = name;
        input.value = value;
        return input;
    };
    let confirmRefund=function(){
        let selectRows = eyc.pqGrid.getSelectRows(order.$table);
        if(selectRows != null && selectRows.length > 0){
            let rowData=selectRows[0].rowData;
            parent.layer.open({
                type: 2,
                title: '商户维护',
                area: ['450px', '300px'],
                content: '/page/orderRefund',
                success: function (layero, index) {
                    if (rowData) {
                        let iframeWin = parent.window[layero.find('iframe')[0]['name']];
                        iframeWin.initData(rowData);
                    }

                }
            });

        }
    }
    let verificationOrders=function(){
        let selectRows = eyc.pqGrid.getSelectRows(order.$table);
        if(selectRows != null && selectRows.length > 0){
           let orderNums= $.map(selectRows,function (r) {
                return r.rowData.orderNum;
            });
            eyc.ajax.promise('/eyc/verificationOrders',orderNums).then(res=>{
                if(res.data){
                    parent.layer.msg('核销成功~~');
                    order.$table.pqGrid("refreshDataAndView");
                }
            });
        }
    };
    $(function () {
        layui.use(['form', 'laydate'], function () {
            let form = layui.form;
            let laydate = layui.laydate;
            initTable();
            initSelectPage();
            initLaydate(laydate);
        });
        $('body').on('click','button[data-method]',function(){
            var fun=eval($(this).data().method);
            new fun($(this).data());
        });
    });
    window.refreshData=function () {
        order.$table.pqGrid("refreshDataAndView");
    };